package com.huc.netty.serial;

import com.alibaba.fastjson.JSON;
import com.huc.netty.constants.SerialType;



/**
 * @author huc
 * @version 1.0
 * @note json序列化
 * @date 2021/9/16 10:6
 */
public class JsonSerializer implements ISerializer {
    @Override
    public <T> byte[] serialize(T obj) {
        return JSON.toJSONString(obj).getBytes();
    }

    @Override
    public <T> T deserialize(byte[] data, Class<T> clazz) {
        return JSON.parseObject(new java.lang.String(data), clazz);
    }

    @Override
    public byte getType() {
        return SerialType.JSON_SERIAL.code();
    }
}
